<?php

session_start();

header('Content-Type: application/json');

class MyDB extends SQLite3 {
	function __construct() {
		$this->open('access.db');
	}
}

$db = new MyDB();

if(!$db) { 
		echo $db->lastErrorMsg();
}

$json = array();

$count_sql = "select count(id) as count from vacation";

$results = $db->query($count_sql);
	while ($row = $results->fetchArray(SQLITE3_ASSOC)) {
		$count = $row['count'];
	}

for($i=1;$i<$count+1;$i++) {
	$sql_access = "select title, date_start as start, date_end as end from vacation where uid='".$_SESSION['uid']."' and id = ".$i;
	//echo $sql_access;
	$results = $db->query($sql_access);
	while ($row = $results->fetchArray(SQLITE3_ASSOC)) {
		if(empty($row['end'])) {
			$date = date('Y-m-d H:i:s');
			$row['end'] = $date;
		}
		//$row['title'] = "urlop wypoczynkowy";
		$row['color'] = "#24870f";
		//$row['editable'] = "true";
		array_push($json, $row);
	}
}

$json_data = json_encode($json);

echo $json_data;

$db->close();

?>